package com.eachonline.smart.service.imp;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eachonline.core.Pagination;
import com.eachonline.mapper.GenericMapper;
import com.eachonline.service.GenericServiceImpl;
import com.eachonline.smart.mapper.SmartCourseMapper;
import com.eachonline.smart.model.SmartCourse;
import com.eachonline.smart.model.SmartCourseExample;
import com.eachonline.smart.model.base.BaseSmartCourseExample.Criteria;
import com.eachonline.smart.service.CourseService;
import com.eachonline.util.StringUtil;
@Service
public class CourseServiceImp extends GenericServiceImpl<SmartCourse, SmartCourseExample, String> implements CourseService {

	@Autowired
	private SmartCourseMapper  smartCourseMapper;

	@Override
	protected GenericMapper<SmartCourse, SmartCourseExample, String> getGenericMapper() {
		// TODO Auto-generated method stub
		return this.smartCourseMapper;
	}

	@Override
	public Pagination<SmartCourse> queryCourseList(int start, int pageSize,String site,String courseType,String courseLevel,String courseCategory,String courseName,String courseRank) {
		// TODO Auto-generated method stub
		SmartCourseExample  courseEx=new SmartCourseExample();
		Criteria  cr=courseEx.createCriteria();
		if(StringUtil.isNotEmpty(site))
		{
			cr.andCourseSiteEqualTo(site);
		}
		if(StringUtil.isNotEmpty(courseCategory))
		{
			cr.andCourseCategroyCodeLike(courseCategory+"%");
		}
		
		if(StringUtil.isNotEmpty(courseLevel))
		{
			cr.andCourseLevelEqualTo(courseLevel);
		}
		
		if(StringUtil.isNotEmpty(courseName))
		{
			cr.andCourseNameLike(courseName);
		}
		
		if(StringUtil.isNotEmpty(courseRank))
		{
			cr.andCourseRankEqualTo(courseRank);
		}
		
		cr.andCheckStatusEqualTo("2");
		return queryByPage(courseEx, start, pageSize," create_time desc");
	}

	
	

	@Override
	public Pagination<SmartCourse> queryMangerCourseList(int start, int pageSize,String status,String courseType,String courseLevel,String courseCategory,String courseName,String courseRank,String userName,String site) {
		// TODO Auto-generated method stub
		SmartCourseExample  courseEx=new SmartCourseExample();
		Criteria  cr=courseEx.createCriteria();
		if(StringUtil.isNotEmpty(status))
		{
			cr.andCheckStatusEqualTo(status);
		}
		if(StringUtil.isNotEmpty(courseCategory))
		{
			cr.andCourseCategroyCodeLike(courseCategory+"%");
		}
		
		if(StringUtil.isNotEmpty(courseLevel))
		{
			cr.andCourseLevelEqualTo(courseLevel);
		}
		if(StringUtil.isNotEmpty(site))
		{
			cr.andCourseSiteEqualTo(site);
		}
		if(StringUtil.isNotEmpty(courseRank))
		{
			cr.andCourseRankEqualTo(courseRank);
		}
		if(StringUtil.isNotEmpty(courseName))
		{
			cr.andCourseNameLike("%"+courseName+"%");
		}
		
		
		return queryByPage(courseEx, start, pageSize," create_time desc");
	}
	
	@Override
	public Pagination<SmartCourse> queryTeacherCourseList(int start, int pageSize,String teacherId,String courseType,String courseLevel,String courseCategory,String courseName,String courseRank) {
		// TODO Auto-generated method stub
		SmartCourseExample  courseEx=new SmartCourseExample();
		Criteria  cr=courseEx.createCriteria();
		if(StringUtil.isNotEmpty(teacherId))
		{
			cr.andTeacherIdEqualTo(teacherId);
		}
		if(StringUtil.isNotEmpty(courseType))
		{
			cr.andCourseTypeEqualTo(courseType);
		}
		
		if(StringUtil.isNotEmpty(courseLevel))
		{
			cr.andCourseLevelEqualTo(courseLevel);
		}
		
		if(StringUtil.isNotEmpty(courseRank))
		{
			cr.andCourseRankEqualTo(courseRank);
		}
		
		
		if(StringUtil.isNotEmpty(courseName))
		{
			cr.andCourseNameLike(courseName);
		}
		
		if(StringUtil.isNotEmpty(courseCategory))
		{
			cr.andCourseCategroyEqualTo(courseCategory);
		}
		return queryByPage(courseEx, start, pageSize," create_time desc");
	}

	@Override
	public Pagination<SmartCourse> queryCourseListBySort(int start,
			int pageSize, String site, String courseType, String courseLevel,
			String courseCategory, String courseName, String courseRank,
			String sort) {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
				SmartCourseExample  courseEx=new SmartCourseExample();
				Criteria  cr=courseEx.createCriteria();
				if(StringUtil.isNotEmpty(site))
				{
					cr.andCourseSiteEqualTo(site);
				}
				if(StringUtil.isNotEmpty(courseCategory))
				{
					cr.andCourseCategroyCodeLike(courseCategory+"%");
				}
				
				if(StringUtil.isNotEmpty(courseLevel))
				{
					cr.andCourseLevelEqualTo(courseLevel);
				}
				
				if(StringUtil.isNotEmpty(courseName))
				{
					cr.andCourseNameLike(courseName);
				}
				
				if(StringUtil.isNotEmpty(courseRank))
				{
					cr.andCourseRankEqualTo(courseRank);
				}
				
				cr.andCheckStatusEqualTo("2");

				String str=" create_time desc";
				if(StringUtil.isNotEmpty(sort))
				{
					str=sort+","+str;
				}
				return queryByPage(courseEx, start, pageSize,str);
	}

}